﻿using System; 
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLPropertyGrid;
using SLPropertyGrid.Converters;

namespace FormDesigner
{
    [DataContract]
    public class HtmlCheckBoxModel
    {
        private string textid;
        private string text;
        private int location_x;
        private int location_y;

        public CheckBox ctrl;

        public HtmlCheckBoxModel(CheckBox htmlcheckbox)
        {
            this.ctrl = htmlcheckbox;
        }

        [Editor(typeof(TextIdValueEditor))]
        [DataMember]
        [SLPropertyGrid.DisplayName("关联项")]
        [System.ComponentModel.Description("于该控件关联的文本")]
        public string TextId
        {
            get { return textid; }
            set { this.textid = value; }
        }
        [DataMember]
        [SLPropertyGrid.DisplayName("文本")]
        [System.ComponentModel.Description("用于描述改控件用途")]
        public string Text
        {
            get { return text; }
            set
            {
                this.text = value;
                if (this.ctrl != null)
                    this.ctrl.Content = this.text;
            }
        }
        [System.ComponentModel.Category("Numeric Float")]
        [DataMember]
        [Browsable(false)]
        public int LocationX
        {
            get
            {
                return ctrl != null ? location_x = (int)Canvas.GetLeft(ctrl) : location_x;
            }
            set
            {
                location_x = value;
                if (ctrl != null)
                    Canvas.SetLeft(ctrl, value);
            }
        }
        [DataMember]
        [Browsable(false)]
        public int LocationY
        {
            get
            {
                return ctrl != null ? location_y = (int)Canvas.GetTop(ctrl) : location_y;
            }
            set
            {
                location_y = value;
                if (ctrl != null)
                    Canvas.SetTop(ctrl, value);
            }
        }

        public string ExtProperty()
        {
            if (!string.IsNullOrEmpty(TextId))
                return string.Format(" type=\"checkbox\" name=\"{0}\"", TextId);
            else
                return " type=\"checkbox\"";
        }

    }

}
